package org.fuxia.im.core.service;

import org.fuxia.im.core.entries.ECPacket;
import org.fuxia.im.core.server.ServerSideContext;

/**
 * 客户端请求处理转发类
 *
 */
public class DispathService
{

	/**
	 * 转发客户端请求到相应的Service上
	 * @param paket
	 */
	public static void dispath(ECPacket paket)
	{
		ECService service = ServerSideContext.getContext().getSpringContext().getBean(paket.getMessageType(), ECService.class);
		Executor.executeService(service, paket);
	}

	/**
	 * 处理客户端请求的服务线程 
	 *
	 */
	public static class Executor extends Thread
	{

		private ECService	service;
		private ECPacket	packet;

		public static void executeService(ECService service , ECPacket packet)
		{
			Executor executor = new Executor();
			executor.service = service;
			executor.packet = packet;
			executor.start();
		}

		public void run()
		{
			service.service(packet);
		}
	}
}
